package com.qidian.buy.cms.controller;

import com.qidian.buy.cms.util.QiniuTools;
import com.qidian.buy.common.pojo.BuyResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


/**
 * @author 戴着假发的程序员
 * @company 起点编程
 * @date 2024/6/13 15:44
 */
@RestController
@CrossOrigin
@RequestMapping("/upload")
public class UploadController {
    @Autowired
    private QiniuTools qiniuTools;
    @RequestMapping
    public BuyResult upload(@RequestParam(value = "uploadFile") MultipartFile uploadFile) throws IOException {
        // 获取已经上传到服务器的文件的字节数组数据
        byte[] bytes = uploadFile.getBytes();
        // 使用工具将这个文件上传到云服务器
        String url = qiniuTools.uploadFile(bytes);
        // 响应客户端
        return BuyResult.success(url);
    }
}
